#!/usr/bin/env python
# encoding=utf-8

import sys

from flask.ext.wtf import Form
from wtforms import StringField, PasswordField, BooleanField, SubmitField
from wtforms.validators import Length, Regexp, EqualTo, DataRequired

reload(sys)
sys.setdefaultencoding('utf-8')


class SigninForm(Form):
    username = StringField(u'用户名', validators=[
        DataRequired(),
        Length(4, 20, message=u'用户名需要为4-20位字母或数字组成，首位只能为字母'),
        Regexp(ur'^[a-zA-Z][a-zA-Z0-9_]*$', 0, u'用户名必须为4-20位字母或数字组成，首位只能为字母')
    ])
    password = PasswordField(u'密码', validators=[
        DataRequired(),
        Length(6, 18, message=u'密码长度需为6-16位'),
    ])
    remember = BooleanField(u'记住我')
    submit = SubmitField(u'登录')


class SignupForm(Form):
    username = StringField(u'用户名', validators=[
        DataRequired(),
        Length(4, 20, message=u'用户名必须为4-20位字母或数字组成，首位只能为字母'),
        Regexp(ur'^[a-zA-Z][a-zA-Z0-9_]*$', 0, u'用户名必须为4-20位字母或数字组成，首位只能为字母')
    ])
    phone = StringField(u'手机号码', validators=[
        DataRequired(),
        Length(11, 11, message=u'手机号码必须为11位数字'),
        Regexp(ur'^\d+$', 0, u'手机号码必须为11位数字')
    ])
    password = PasswordField(u'密码', validators=[
        DataRequired(),
        EqualTo(u'password2', message=u'两次输入的密码不一致'),
        Length(6, 18, message=u'密码必须在6-18位之间')
    ])
    password2 = PasswordField(u'确认密码', validators=[DataRequired()])

    submit = SubmitField(u'注册')

    def validate_phone(self, phone):
        pass

    def validate_username(self, username):
        pass
